<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">

      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="招聘单位">
          <a-input placeholder="请输入招聘单位" v-decorator="['company', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="单位信息">
          <a-input placeholder="请输入单位信息" v-decorator="['information', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="招聘岗位">
          <a-input placeholder="请输入招聘岗位" v-decorator="['position', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位职责">
          <a-input placeholder="请输入岗位职责" v-decorator="['duty', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="岗位要求">
          <a-input placeholder="请输入岗位要求" v-decorator="['requirements', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工作经验">
          <a-input placeholder="请输入工作经验要求" v-decorator="['workExperience', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学历要求">
          <a-input placeholder="请输入学历要求" v-decorator="['degreeLimit', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工作地点">
          <a-input placeholder="请输入工作地点" v-decorator="['workPlace', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="薪资待遇">
          <a-input placeholder="请输入薪资待遇" v-decorator="['salary', {}]"/>
       </a-form-item>
       <a-form-item
         :labelCol="labelCol"
         :wrapperCol="wrapperCol"
         label="福利待遇">
         <a-input placeholder="请输入福利待遇" v-decorator="['socialBenefits', {}]"/>
      </a-form-item>
      <a-form-item
         :labelCol="labelCol"
         :wrapperCol="wrapperCol"
         label="招聘人数">
         <a-input placeholder="请输入招聘人数" v-decorator="['absorbAmount', {}]"/>
      </a-form-item>
        <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="发布日期">
            <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="['issueTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入主键" type="hidden" v-decorator="['pkAbsorb', validatorRules.pkAbsorb ]"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    name: "recruitmentAbsorbModal",
    mixins:[JeecgListMixin],
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          //pkManagement:{rules: [{ required: true, message: '请输入主键!' }]},
        },
        url: {
          list: "/recruitment/recruitmentAbsorb/list",
          add: "/recruitment/recruitmentAbsorb/add",
          edit: "/recruitment/recruitmentAbsorb/edit"
        },
      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'pkAbsorb','company','information','position','duty','workExperience', 'workPlace','salary','socialBenefits','requirements','degreeLimit','absorbAmount', 'issueTime'))
          //时间格式化
          this.form.setFieldsValue({issueTime: this.model.issueTime ? moment(this.model.issueTime) : null})
        });

      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            console.log(this.model.pkAbsorb);
            if (!this.model.pkAbsorb) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.issueTime = formData.issueTime ? formData.issueTime.format('YYYY-MM-DD HH:mm:ss') : null;

            console.log(this)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })


          }
        })
      },
      handleCancel() {
        this.close()
      }
    },
  }
</script>

<style lang="less" scoped>

</style>